#+TITLE: OpenBSD
#+AUTHOR: Joshua Branson
#+STARTUP: overview



* this is a good guide to help install your openBSD system in qemu

  https://wiki.qemu.org/Hosts/BSD#VM_setup_2

* after install run =man afterboot=

* read /usr/X11R6/README

* Installing packages is

  #+BEGIN_SRC sh :results output :exports both
    pkg_add -v chromium emacs
  #+END_SRC

* lots of the openBSD configuration is found in =/etc/rc.conf=.

  I should not hand edit =/etc/rc=.

  Most of my edits should go in =/etc/rc.local=.

  =/etc/examples= has good configuration options

* building software yourself:

  from here: https://wiki.qemu.org/Hosts/BSD#VM_setup_2

  Make sure that the filesystem you're building and running QEMU from has the "wxallowed" option set in /etc/fstab, like:

 d3651b0622794af6.k /home ffs rw,wxallowed,nodev,nosuid 1 2

then either reboot or use "mount -uo wxallowed /wherever" to set it for this session. (This is necessary because QEMU assumes it can map memory RWX for TCG and 'make check' will fail if it can't.) 

* updating the system is done via =syspatch= 
* I have to enable doas

  I have to create the file =/etc/doas.conf=.

* I need to enable X via =/etc/rc.conf.local=.

  Or via the command

  #+BEGIN_SRC sh :results output :exports both
    rcctl enable xenodm
    rcctl start xenodm
  #+END_SRC

* In order to boot OpenBSD I may need to use =rEFInd=

  However from this page

  https://www.rodsbooks.com/refind/installing.html#manual

  =rEFInd= may only work for booting UEFI

  This webpage seems to say the same:

  https://wiki.archlinux.org/title/REFInd#Installing_the_rEFInd_Boot_Manager

https://www.openbsd.org/faq/faq4.html#Multibooting
  
rEFInd is reported to usually work. GRUB is reported to usually
fail. In either case, you are completely on your own.

I should also ensure that the root partition for OpenBSD is using one
of the primary MBR partitions.  Using an extended root partition may
not work.

* I could help the openBSD project by just purchasing hardware:

  https://www.openbsd.org/want.html

* what kind of hardware does openBSD run on:

  Old Thinkpads!

  https://www.reddit.com/r/openbsd/comments/byrxte/what_laptoppc_for_using_openbsd_with_a_desktop/


  Old AMD laptops.
  https://www.openbsd.org/amd64.html

* basic install book

  https://www.openbsdhandbook.com/installation/

* getting xfce to work in openBSD 

  https://opensource.com/article/20/10/old-hardware-openbsd

* the openBSD amd64 boot process:

  https://www.openbsd.org/faq/faq14.html#BootAmd64

  It looks like openBSD includes its own bootloader that it installs
  in the PBR (partition boot record), which is the first 512 bytes of
  the MBR...I think.  That may be mis-stated.
  
* the libreboot guide for using openBSD says that libreboot can boot openBSD 6.1.

  It also recommends to use the seabios payload to boot openBSD.

  https://libreboot.org/docs/bsd/openbsd.html

  GRUB supports booting OpenBSD kernels directly. However, you’re
  better off simply using the SeaBIOS payload; BSD works well with
  BIOS or UEFI setups.

  This guide is written for OpenBSD 6.1, but it can be adapted easily
  for other versions (of OpenBSD).

  #+BEGIN_SRC sh :results output :exports both
    grub> kopenbsd (usb0,openbsd1)/6.1/amd64/bsd.rd
    grub> boot
  #+END_SRC

* here are some unofficial openBSD forums:

  http://daemonforums.org/index.php

* I can try to install openBSD by creating a boot-able cd rom! 
* what is this site?  http://www.openbsdsupport.org/  
* apparently libreboot/coreboot does NOT support chainloading  

  https://www.gnu.org/software/grub/manual/grub/html_node/Supported-kernels.html

* how to install openBSD via libreboot awesome mailing list post


  openBSD may have a hard time booting because it makes BIOS calls
  and/or the libreboot video BIOS replacement.  It might be possible
  to boot openBSD in text-only mode...

  This is a VERY detail guide for the X200.  Apparently openBSD.  It
  talks a lot about the framebuffer support.
  https://lists.gnu.org/archive/html/libreboot/2016-04/msg00010.html


  A good mailing list email:

  https://lists.gnu.org/archive/html/libreboot/2015-05/msg00003.html

 
  Another good mailing list post about SeaBIOS:

  https://lists.gnu.org/archive/html/libreboot/2015-10/msg00017.html

  
  I should probably NOT try any of this:
  https://www.endeer.cz/bios.tools/bios.html

  This guys knows lots about libreboot
  https://www.quietlife.nl/

* conversation with leah rowe:

  <jab> Hello osboot people!  I'm trying to play around with openBSD...and I'm
      trying to boot openBSD via osboot...  [12:21]
<leah> grub payload right?
<leah> do you have seabios available in the grub boot menu?
<leah> if so, select seabios
<jab> I've tried the grub payload and the seabios payload.
<leah> use that for openbsd
<leah> oh right, yeah do you have corebootfb or txtmode rom?
<leah> when you boot, does the text in grub look like it's really low res. or
       does it look like native resolution  [12:22]
<leah> use a rom with txtmode in the file name, and use seabios
<leah> that's the most reliable way to boot openbsd
<jab> leah, I actually don't know...you built an image for me.  I was probably
      one of the first osboot users.  You quickly made me an image for a
      T400...
<leah> ah
<leah> t400
<leah> just switch to libreboot 20210522  [12:23]
<leah> but
<leah> before you do: if the reason you want osboot is because microcode, tell
       me and i'll tell you how to extract that from your current osboot rom,
       and insert it into the libreboot rom
<leah> i recommend using libreboot 20210522 on that machine
<leah> at the time of giving you an osboot rom for it, osboot was more up to
       date than libreboot
<jab> yes.  I do want to use microcode.  without it my computer crashes like
      once a week.  :( 
<leah> now libreboot is more up to date. osboot uses coreboot 4.13 at
       present. libreboot uses 4.14  [12:24]
<leah> ok, do this for me:
<leah> sudo flashrom -p internal -r dump.bin
<jab> just a second
<leah> show me the output of this command, on a paste site
<leah> the -r option dumps your current rom to a file. we will be extracting
       the microcode from that
<jab> will do...for now, I'll have to reboot with the linux option "relaxed"
      or something...I'll be back in a bit.  [12:25]
<leah> yes
<jab> also you may be the most helpful and responsive free software maintainer
      that I know!
<jab> may I ask about the next osboot release/future direction?  just curious.
                                                                        [12:26]
<jab> also how out of date is this guide:
      https://lists.gnu.org/archive/html/libreboot/2016-04/msg00010.html  
ERC> 


<jab> ok leah, my pastbin:  [12:43]
<jab> https://paste.debian.net/1204696/  

Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
joshua@dobby ~> sudo flashrom -p internal -r dump.bin
Password: 
flashrom v1.2 on Linux 5.12.16-gnu (x86_64)
flashrom is free software, get the source code at https://flashrom.org

Using clock_gettime for delay loops (clk_id: 1, resolution: 1ns).
coreboot table found at 0x7f770000.
Found chipset "Intel ICH9M-E".
Enabling flash write... OK.
Found Macronix flash chip "MX25L6405" (8192 kB, SPI) mapped at physical address 0x00000000ff800000.
Found Macronix flash chip "MX25L6405D" (8192 kB, SPI) mapped at physical address 0x00000000ff800000.
Found Macronix flash chip "MX25L6406E/MX25L6408E" (8192 kB, SPI) mapped at physical address 0x00000000ff800000.
Found Macronix flash chip "MX25L6436E/MX25L6445E/MX25L6465E/MX25L6473E/MX25L6473F" (8192 kB, SPI) mapped at physical address 0x00000000ff800000.
Multiple flash chip definitions match the detected chip(s): "MX25L6405", "MX25L6405D", "MX25L6406E/MX25L6408E", "MX25L6436E/MX25L6445E/MX25L6465E/MX25L6473E/MX25L6473F"
Please specify which chip definition to use with the -c <chipname> option.


<leah> ok, do this:  [12:44]
<leah> sudo flashrom -p internal -r dump.bin -c MX25L6405D
<leah> tell me when that's finished, and i'll tell you the next step
<jab> will do.  thanks again for the help!
<leah> this should only take a few minutes. the rest is easy
<leah> openbsd works well with the latest libreboot release  [12:45]
<jab> done.  I now have a dump.bin file.  :)  
<leah> now download the libreboot 20160907 util archive
<jab> ok. will do.
<leah> yes 20160907. it'll work. we need cbfstool
<leah> btw you said i'm responsive. that's only because i'm drinking tea and
       watching My Hero Academia. IRCing is tolerable  [12:48]
<leah> later i'll be in the lab doing some laptops. i'm bringing my shop back
       in stock
<leah> also i have 2 websites i need to launch like, 1 week ago
<leah> i'll try to get them done today
<leah> i woke up about an hour or so ago and i'm still waking up. i build up
       my strength for a few hours, mentally, and then work flat out for about
       12 hours. then relax an hour or so, then i go to bed  [12:49]
<leah> during the 12 hour period, i don't respond on IRC at all. but i do
       respond to emails during that time (business emails)
<jab> ok.  don't beat yourself up.  :)  You've done a ton of awesome work with
      libreboot!  Also, I actually have access to a ton of dell optiplex
      7020s.  I'm not certain what the coreboot support there is...but I've
      been having fun playing with some old computers.  [12:50]
<leah> but there's always someone else to answer, if i'm not available on IRC
<leah> do you have cbfstool yet?
<leah> you need cbfstool. grab it from libreboot 20160907 util archive
<jab> I do have a libreboot_r20160907 directory.  
<jab> and it has a cbfstool directory.
<leah> cbfstool/x86_64/ go in there and there should be a executable
<leah> cbfstool
<leah> copy that to the same directory as dump.bin
<jab> yup  [12:51]
<jab> will do
<jab> check
<leah> you dumped as root, so
<leah> sudo chown user:user dump.bin
<leah> user is your username
<jab> done  [12:52]
<leah> ./cbfstool dump.bin extract -n cpu_microcode_blob.bin -f
       cpu_microcode_blob.bin
<jab> ok.  I now have a cpu_microcode_blob.bin file.    [12:53]
<leah>
       https://rsync.libreboot.org/testing/20210522/roms/libreboot-20210522_t400_8mb.tar.xz
<leah> extract this archive
<jab> ok. just a moment.  [12:54]
<leah> oh, tell me what keyboard layout you have
<leah> oh, wait. it doesn't matter. it's seabios. there's only 1
<leah> from that archive, copy the following file to the same directory as
       dump.bin:  [12:55]
<leah> seabios_grubfirst_t400_8mb_libgfxinit_txtmode_usqwerty.rom
<jab> I do have the dvorak layout...at least that's what I like...
<leah> ah ok  [12:56]
<leah> in that case, choose this file instead:
<leah> seabios_grubfirst_t400_8mb_libgfxinit_txtmode_usdvorak.rom
<leah> it's american dvorak yes?
<jab> yes!
<leah> ok, copy the above file to the same location as dump.bin
<jab> ok will do
<leah> and rename the libreboot rom to libreboot.rom
<leah> makes it easier for me to help  [12:57]
<leah> one thing:
<leah> ip a
<leah> do that command. based on the output, tell me the mac address of your
       onboard ethernet device
<jab> hahaha...ummm I am still using the default mac address of the default
      libreboot...I never fixed that...give me one second though...and I'll
      get it from the back of the laptop...  [12:58]
<leah> in that case, also copy ich9gen from the util archive  [12:59]
<jab> will do.  [13:00]
<jab> ok.  I've renamed libreboot to libreboot.rom...and I've copied the
      ich9gen command.  [13:03]
<leah> ./ich9gen --macaddress bla:bla:bla:bla:bla:bla
<jab> will do
<leah> replace bla with the right numbers
<jab> ok.  I now have several files beginning with ich9f*    [13:04]
<leah> dd if=ich9fdgbe_8m.bin of=libreboot.rom bs=1 count=12k conv=notrunc
                                                                        [13:05]
<leah> ./cbfstool libreboot.rom add -f cpu_microcode_blob.bin -n
       cpu_microcode_blob.bin -t microcode  [13:06]
<leah> ./cbfstool libreboot.rom print
<leah> show me a paste of that last command, and then do:
<leah> hexdump libreboot.rom > libreboot.hex  [13:07]
<leah> less libreboot.hex
<jab> ./cbfstool libreboot.rom add command gave this error:
<leah> at offset 1000 and 2000 should be the mac address that you inserted
<jab> E: Selected image region is not a valid CBFS.
<jab> I probably did something wrong...  [13:08]
<leah> nah  [13:09]
<leah> it's my fault
<leah> i fucked up
<jab> that's ok.
<leah> just email me your microcode file, and the files that ich9gen made
<leah> leah@libreboot.org
<leah> send these in an attachment now
<jab> also just pointing out...I'm hoping to dual boot guix system and
      openBSD.  I'm just wanting to play around with openBSD...I've never used
      it before.
<jab> will do.
<leah> i'll just make the rom for you. libreboot 20210522 rom with your
       microcode and correct mac address
<jab> thanks.  sending shortly...  [13:10]
<leah> guix will also work, in the rom i'm giving you
<jab> ok.  Thanks!  [13:12]
<jab> how big should the libreboot.rom image me?  [13:13]
<jab> 8MB?  right?
<jab> somehow I have a 12KB librebot.rom (1 "o") file...  
ERC> 


<leah> yes there is a way ,hang on
<leah>         tar -c "rom/" | xz -9e >"rom.tar.xz"  [13:17]
<leah> put everything in a directory called "rom"
<jab> will do.
<leah> and do that. then send me rom.tar.xz
<leah> that should make it compress down real tight  [13:18]
<jab> ok.  I just sent it.  I actually have to start getting ready for work.
      Thanks again for your massive help!  [13:21]
<leah> i have you now
<leah> stand by  [13:22]
<leah> jab: check your email  [13:34]
<leah> download the attached archive and extract it. there is a rom inside,
       named libreboot.rom
<leah> it has the correct mac address and microcode inserted  [13:35]
<leah> sudo flashrom -p internal -w libreboot.rom -c MX25L6405D
<jab> thanks!  I've got to run to work now.  I'll test it later...I am a
      little conscerned about bricking my machine...at some point in my
      directory I ended with with a "libreboot.rom" file that was only 12KB...
<leah> do that, and when it says "VERIFIED", just shut down, and wait a few
       seconds. then boot up. you'll be on the latest libreboot
<leah> jab: yes that was my mistake earlier
<jab> ok. gotcha.  [13:36]
<leah> i fucked up the dd command earlier
<leah> that's why the rom ended up being 12KiB
<jab> ok.  I understand now.
<leah> but i've tested this rom that i sent you
<leah> it should work
<jab> oh wow!
<leah> just flash it
<leah> sudo flashrom -p internal -w libreboot.rom -c MX25L6405D
<leah> it should say "VERIFIED" after. then shut down. boot up after a few
       seconds
<jab> leah you are seriously an amazing and wonderful person.  I have to go to
      work like 5 minutes ago, but I'll test it when I get back.  thanks
      again!
<leah> prepare your OpenBSD usb media the way openbsd.org recommends, and boot
       it from seabios. press ESC in SeaBIOS to access the menu, and select
       your USB drive  [13:37]
<leah> you're welcome!
ERC>

Install this to maintain my battery life.
https://dataswamp.org/~solene/2022-03-21-openbsd-cool-frequency.html
